import {h} from 'vue'
import {DataTableColumns, NButton, NSwitch, NTag} from 'naive-ui'

// 点击类型枚举
export enum ClickType {
  DETAILS = 'details',
  NONE = 'no'
}

// 默认的菜单模型
export const DEFAULT_MENU_MODEL: Log.BaseInfo = {
  //ID
  operateId: 0,
  //标题
  title: '',
  //业务类型，字典
  businessType: '',
  //方法名称
  method: '',
  //请求方式
  requestMethod: '',
  //操作人员的昵称
  operateName: '',
  //请求URL
  operateUrl: '',
  //主机地址
  operateIp: '',
  //请求参数
  operateParam: '',
  //返回参数
  jsonResult: '',
  //状态
  status: '',
  //错误消息
  errorMsg: '',
  //操作时间
  operateTime: '',
  //耗时
  costTime: '',
  //时间单位
  timeUnit: '',
}

// 表单规则
export const useFormRules = () => {
  return {}
}

// 表格列配置
export const useColumns = (handleClick: (type: ClickType, row: Log.BaseInfo) => void): DataTableColumns => {
  return [
    {
      title: '标题',
      resizable: true,
      key: 'title',
      align: 'center',
    },
    {
      title: '请求方法',
      resizable: true,
      key: 'method',
      align: 'center',
      ellipsis: {
        tooltip: true
      }
    },
    {
      title: '请求方式',
      resizable: true,
      key: 'requestMethod',
      align: 'center',
      ellipsis: {
        tooltip: true
      }
    },
    {
      title: '操作人员名称',
      resizable: true,
      key: 'operateName',
      align: 'center',
    },
    {
      title: '请求URL',
      resizable: true,
      key: 'operateUrl',
      align: 'center',
      ellipsis: {
        tooltip: true
      }
    },
    {
      title: '主机地址',
      resizable: true,
      align: 'center',
      key: 'operateIp',
    },
    {
      title: '状态',
      resizable: true,
      key: 'status',
      align: 'center',
      render(row: Log.BaseInfo) {
        return h(
          NTag,
          {
            style: {
              marginRight: '6px'
            },
            type: row.status === 'SUCCESS' ? "info" : "error",
            bordered: false
          },
          {
            default: () => row.status
          }
        )
      },
    },
    {
      title: '操作时间',
      resizable: true,
      key: 'operateTime',
      align: 'center',
    },
  ]
}

// 右键菜单选项
export const useContextOptions = (handleClick: (type: ClickType, row: Log.BaseInfo) => void) => {
  return [
    {
      label: '查看详情',
      key: 'details',
      onClick: (row: Log.BaseInfo) => {
        handleClick(ClickType.DETAILS, row)
      }
    },
  ]
}

// Modal样式配置
export const modalStyle = {
  width: '600px'
}
